home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK1.toast / Development Kits (Disc 1) / QuickTime / Programming Stuff / Documentation / develop articles / develop Issue 23 / Internet Config / IC 1.1 / ICAppSourceKit1.1 / ICFileMapWhat.p < prev    next >
Encoding:
Text File  |  1995-04-26  |  19.4 KB  |  665 lines  |  [TEXT/PJMM]

  1. unit ICFileMapWhat;
  2.  
  3. interface
  4.  
  5.     uses
  6.         ICWindowGlobals;
  7.  
  8.     function WhatOpenFileMap (wt: WindowType; item: integer): OSErr;
  9.     function WhatActivateFileMap (wt: WindowType; item: integer; activate: boolean): OSErr;
  10.     function WhatFlushFileMap (wt: WindowType; item: integer): OSErr;
  11.     function WhatCloseFileMap (wt: WindowType; item: integer): OSErr;
  12.     function WhatClickFileMap (wt: WindowType; item: integer; er: eventRecord): OSErr;
  13.     function WhatKeyFileMap (wt: WindowType; item: integer; er: EventRecord): OSErr;
  14.     function WhatCursorFileMap (wt: WindowType; item: integer; pt: Point; cursorid: integer): OSErr;
  15.  
  16. implementation
  17.  
  18.     uses
  19.         IconFamilies, ICStrH, 
  20.  
  21.         ICKeys, ICAPI, ICSubs, ICDialogs, ICMiscSubs, ICSubs, ICDocUtils, ICGlobals, {}
  22.         ICIConSuites, ICStandardFile, ICMovableModal;
  23.  
  24.     const
  25.         ditChange = 1;
  26.         ditMainUserItem = 2;
  27.         ditAdd = 3;
  28.         ditDelete = 4;
  29.         ditList = 5;
  30.  
  31.     const
  32.         ditOK = 1;
  33.         ditCancel = 2;
  34.         ditEditorUserItem = 3;
  35.         ditEntryName = 4;
  36.         ditExtension = 5;
  37.         ditMIMEType = 6;
  38.         ditAsciiRadio = 7;
  39.         ditBinaryRadio = 8;
  40.         ditMacintoshRadio = 9;
  41.         ditType = 10;
  42.         ditCreator = 11;
  43.         ditChooseExample = 12;
  44.         ditApplicationName = 13;
  45.         ditPost = 14;
  46.         ditPostCreator = 15;
  47.         ditPostButton = 16;
  48.         ditNotForIncoming = 17;
  49.         ditNotForOutgoing = 18;
  50.  
  51.     const
  52. (* ditOK = 1; *)
  53. (* ditCancel = 2; *)
  54.         ditManualUserItem = 3;
  55.         ditManualType = 4;
  56.         ditManualCreator = 5;
  57.         ditManualApplicationName = 6;
  58.  
  59.     const
  60.         kCellHeight = 36;
  61.  
  62.     procedure DimButtons (wt: WindowType);
  63.         var
  64.             have_selection: boolean;
  65.             dlg: DialogPtr;
  66.             lh: ListHandle;
  67.     begin
  68.         lh := ListHandle(windowinfo[wt].items[ditList]^.spare_data);
  69.         dlg := windowinfo[wt].window;
  70.         have_selection := (SelectedLine(lh) <> -1);
  71.         SetDCtlEnable(dlg, ditAdd, not IsLocked(wt, ditList));
  72.         SetDCtlEnable(dlg, ditDelete, have_selection and not IsLocked(wt, ditList));
  73.         SetDCtlEnable(dlg, ditChange, have_selection and not IsLocked(wt, ditList));
  74.         OutlineDefault1(dlg, ditMainUserItem);
  75.     end; (* DimButtons *)
  76.  
  77.     procedure MyLDEF (message: integer; select: boolean; var r: Rect; the_cell: Cell; offset: integer; datalen: integer; lh: ListHandle);
  78.         var
  79.             entries: Handle;
  80.  
  81.         procedure LDClose;
  82.         begin
  83.             (* do nothing *)
  84.         end;
  85.  
  86.         procedure LDDraw;
  87.             const
  88.                 HiliteMode = $938;
  89.             var
  90.                 entry: ICMapEntry;
  91.                 pos: longint;
  92.                 err: OSErr;
  93.                 junkpos: longint;
  94.                 suite: Handle;
  95.                 cur_x: integer;
  96.                 junk: OSErr;
  97.                 tmprect: Rect;
  98.                 sys_font_info, appl_font_info: FontInfo;
  99.                 top: integer;
  100.                 transfer: integer;
  101.                 rgn: RgnHandle;
  102.                 rgn2: RgnHandle;
  103.         begin
  104.             if datalen = 0 then begin
  105.                 err := ICMapErr(ICGetIndMapEntry(GetInstance, entries, the_cell.v + 1, junkpos, entry));
  106.                 if err = noErr then begin
  107.                     EraseRect(r);
  108.                     cur_x := 0;
  109.                     rgn := NewRgn;
  110.                     if system7 then begin
  111.                         tmprect := r;
  112.                         tmprect.bottom := tmprect.top + 32;
  113.                         tmprect.right := tmprect.left + 32;
  114.                         OffsetRect(tmprect, (kCellHeight - 32) div 2, (kCellHeight - 32) div 2);
  115.                         junk := GetDTDBIconSuiteCached(entry.file_type, entry.file_creator, suite);
  116.                         if suite <> nil then begin
  117.                             if select then begin
  118.                                 transfer := ttSelected;
  119.                             end
  120.                             else begin
  121.                                 transfer := ttNone;
  122.                             end; (* if *)
  123.                             err := PlotIconSuite(tmprect, atNone, transfer, suite);
  124.                             junk := IconSuiteToRgn(rgn, tmprect, atNone, suite);
  125.                         end; (* if *)
  126.                         cur_x := cur_x + kCellHeight;
  127.                     end;
  128.                     cur_x := cur_x + 2;
  129.  
  130.                     TextFont(systemFont);
  131.                     GetFontInfo(sys_font_info);
  132.  
  133.                     TextFont(applFont);
  134.                     GetFontInfo(appl_font_info);
  135.  
  136.                     top := (kCellHeight - (sys_font_info.ascent + sys_font_info.descent + 0 + appl_font_info.ascent + appl_font_info.descent)) div 2;
  137.                     TextFont(systemFont);
  138.                     MoveTo(r.left + cur_x, r.top + top + sys_font_info.ascent);
  139.                     DrawString(concat(entry.creator_app_name, GetAString(128, 5), entry.entry_name));
  140.  
  141.                     TextFont(applFont);
  142.                     MoveTo(r.left + cur_x, r.top + top + sys_font_info.ascent + sys_font_info.descent + 0 + appl_font_info.ascent);
  143.                     DrawString(entry.extension);
  144.  
  145.                     if select then begin
  146.                         rgn2 := NewRgn;
  147.                         RectRgn(rgn2, r);
  148.                         if has_colorQD then begin
  149.                             BitClr(Ptr(HiliteMode), pHiliteBit);
  150.                         end; (* if *)
  151.                         XorRgn(rgn, rgn2, rgn2);
  152.                         InvertRgn(rgn2);
  153.                         DisposeRgn(rgn2);
  154.                     end; (* if *)
  155.                     if rgn <> nil then begin
  156.                         DisposeRgn(rgn);
  157.                     end; (* if *)
  158.                 end; (* if *)
  159.             end;
  160.         end;
  161.  
  162.     begin
  163.         SetPort(lh^^.port);
  164.         entries := Handle(windowinfo[GetWindowType(lh^^.port)].items[ditList]^.data);
  165.         case message of
  166.             lInitMsg: 
  167.                 ;
  168.             lDrawMsg: 
  169.                 LDDraw;
  170.             lHiliteMsg: 
  171.                 LDDraw;
  172.             lCloseMsg: 
  173.                 LDClose;
  174.         end;
  175.     end; (* MyLDEF *)
  176.  
  177.     procedure UserItemUpdate (dlg: DialogPtr; item: integer);
  178.         var
  179.             list_rect: Rect;
  180.     begin
  181.         GetDItemRect(dlg, item, list_rect);
  182.         PenNormal;
  183.         InsetRect(list_rect, -1, -1);
  184.         FrameRect(list_rect);
  185.         LUpdate(dlg^.visRgn, ListHandle(windowinfo[GetWindowType(dlg)].items[item]^.spare_data));
  186.     end; (* UserItemUpdate *)
  187.  
  188.     function WhatOpenFileMap (wt: WindowType; item: integer): OSErr;
  189.         var
  190.             dlg: DialogPtr;
  191.             entries: Handle;
  192.             attr: longint;
  193.             err: OSErr;
  194.             count: longint;
  195.             list_rect: Rect;
  196.             data_rect: Rect;
  197.             cell_size: Point;
  198.             lh: ListHandle;
  199.     begin
  200.         windowinfo[wt].items[item]^.spare_data := nil;
  201.         windowinfo[wt].items[item]^.data := nil;
  202.         err := noErr;
  203.         dlg := windowinfo[wt].window;
  204.         SetDItemHandle(dlg, item, @UserItemUpdate);
  205.         if ICMapErr(ICGetPrefHandle(GetInstance, windowinfo[wt].items[item]^.key, attr, entries)) <> noErr then begin
  206.             entries := NewHandle(0);
  207.             if entries = nil then begin
  208.                 err := memFullErr;
  209.             end; (* if *)
  210.         end; (* if *)
  211.         ProcessAttributes(wt, item, attr);
  212.         if err = noErr then begin
  213.             if ICCountMapEntries(GetInstance, entries, count) <> noErr then begin
  214.                 count := 0;
  215.             end; (* if *)
  216.             windowinfo[wt].items[item]^.data := Ptr(entries);
  217.             GetDItemRect(dlg, item, list_rect);
  218.             list_rect.right := list_rect.right - 15;
  219.             SetRect(data_rect, 0, 0, 1, count);
  220.             SetPt(cell_size, list_rect.right - list_rect.left, kCellHeight);
  221.             lh := LNew(list_rect, data_rect, cell_size, 128, dlg, true, false, false, true);
  222.             if lh = nil then begin
  223.                 err := memFullErr;
  224.             end; (* if *)
  225.         end; (* if *)
  226.         if err = noErr then begin
  227.             lh^^.refCon := ord(@MyLDEF);
  228.             lh^^.selFlags := lOnlyOne;
  229.             windowinfo[wt].items[item]^.spare_data := Ptr(lh);
  230.             DimButtons(wt);
  231.             SetUpDefaultOutline(dlg, ditChange, ditMainUserItem);
  232.             windowinfo[wt].selected_item := ditList;
  233.         end; (* if *)
  234.         WhatOpenFileMap := err;
  235.     end; (* WhatOpenFileMap *)
  236.  
  237.     procedure SetRadio (modal: DialogPtr; value: integer);
  238.     begin
  239.         SetDCtlBoolean(modal, ditAsciiRadio, value = ditAsciiRadio);
  240.         SetDCtlBoolean(modal, ditBinaryRadio, value = ditBinaryRadio);
  241.         SetDCtlBoolean(modal, ditMacintoshRadio, value = ditMacintoshRadio);
  242.     end; (* SetRadio *)
  243.  
  244.     function AddChangeFilter (dlg: DialogPtr; var event: EventRecord; var item: integer): boolean;
  245.         var
  246.             res: boolean;
  247.             ch: char;
  248.     begin
  249.         res := CancelModalFilter(dlg, event, item);
  250.         if not res then begin
  251.             if (event.what = keyDown) and (band(event.modifiers, cmdKey) <> 0) then begin
  252.                 ch := char(band(event.message, charCodeMask));
  253.                 if ch in ['1'..'3'] then begin
  254.                     SetRadio(dlg, ord(ch) - ord('1') + ditAsciiRadio);
  255.                 end; (* if *)
  256.             end; (* if *)
  257.         end; (* if *)
  258.         if InForeground then begin
  259.             if band(event.modifiers, optionKey) = 0 then begin
  260.                 SetDCtlTitle(dlg, ditChooseExample, GetAString(128, 6));
  261.             end
  262.             else begin
  263.                 SetDCtlTitle(dlg, ditChooseExample, GetAString(128, 7));
  264.             end; (* if *)
  265.         end; (* if *)
  266.         AddChangeFilter := res;
  267.     end; (* AddChangeFilter *)
  268.  
  269.     function DoDialog (var entry: ICMapEntry): OSErr;
  270.  
  271.         function MapOSType (ot: OSType): Str15;
  272.         begin
  273.             if ot = OSType(0) then begin
  274.                 MapOSType := '';
  275.             end
  276.             else begin
  277.                 MapOSType := ot;
  278.             end; (* if *)
  279.         end; (* MapOSType *)
  280.  
  281.         function MapStr (s: Str255): OSType;
  282.         begin
  283.             s := copy(concat(s, '    '), 1, 4);
  284.             MapStr := s;
  285.         end; (* MapStr *)
  286.  
  287.         var
  288.             modal: DialogPtr;
  289.  
  290.         procedure DoChooseExample;
  291.             var
  292.                 info: FInfo;
  293.                 err: OSErr;
  294.                 fs, app_fss: FSSpec;
  295.         begin
  296.             err := ICStandardGetFile(OSType(0), fs, info);
  297.             DisplayError(acGetExample, err);
  298.             if err = noErr then begin
  299.                 SetItemText(modal, ditType, MapOSType(info.fdType));
  300.                 SetItemText(modal, ditCreator, MapOSType(info.fdCreator));
  301.                 err := MyGetAPPL(info.fdCreator, app_fss);
  302.                 if err = noErr then begin
  303.                     SetItemText(modal, ditApplicationName, app_fss.name);
  304.                 end
  305.                 else begin
  306.                     SetItemText(modal, ditApplicationName, '');
  307.                 end; (* if *)
  308.             end; (* if *)
  309.         end; (* DoChooseExample *)
  310.  
  311.         function ChoosePost: boolean;
  312.             var
  313.                 info: FInfo;
  314.                 err: OSErr;
  315.                 fs, app_fss: FSSpec;
  316.         begin
  317.             err := ICStandardGetFile('APPL', fs, info);
  318.             DisplayError(acGetExample, err);
  319.             if err = noErr then begin
  320.                 entry.post_creator := info.fdCreator;
  321.                 entry.post_app_name := fs.name;
  322.             end; (* if *)
  323.             ChoosePost := err = noErr;
  324.         end;
  325.  
  326.         procedure DoEditTypeCreator;
  327.             var
  328.                 edit_dlg: DialogPtr;
  329.                 item: integer;
  330.                 tmpstr: Str255;
  331.                 saved_state: Ptr;
  332.         begin
  333.             edit_dlg := GetNewDialog(701, nil, WindowPtr(-1));
  334.             if edit_dlg <> nil then begin
  335.                 GetItemText(modal, ditType, tmpstr);
  336.                 SetItemText(edit_dlg, ditManualType, tmpstr);
  337.                 GetItemText(modal, ditCreator, tmpstr);
  338.                 SetItemText(edit_dlg, ditManualCreator, tmpstr);
  339.                 GetItemText(modal, ditApplicationName, tmpstr);
  340.                 SetItemText(edit_dlg, ditManualApplicationName, tmpstr);
  341.                 SetUpDefaultOutline(edit_dlg, ditOK, ditManualUserItem);
  342.  
  343.                 SelIText(edit_dlg, ditManualType, 0, 32767);
  344.                 ShowWindow(edit_dlg);
  345.                 DisableMenuBar(saved_state, -1);
  346.                 InitCursor;
  347.                 repeat
  348.                     MovableModalDialog(@CancelModalFilter, item);
  349.                 until item in [ditOK, ditCancel];
  350.                 GetItemText(edit_dlg, ditManualType, tmpstr);
  351.                 SetItemText(modal, ditType, tmpstr);
  352.                 GetItemText(edit_dlg, ditManualCreator, tmpstr);
  353.                 SetItemText(modal, ditCreator, tmpstr);
  354.                 GetItemText(edit_dlg, ditManualApplicationName, tmpstr);
  355.                 SetItemText(modal, ditApplicationName, tmpstr);
  356.                 ReEnableMenuBar(saved_state);
  357.                 DisposeDialog(edit_dlg);
  358.             end; (* if *)
  359.         end; (* DoEditTypeCreator *)
  360.  
  361.         procedure SetPostInfo;
  362.         begin
  363.             if entry.post_creator <> OSType(0) then begin
  364.                 SetDCtlTitle(modal, ditPostButton, concat(GetIndStr(128, 24), entry.post_app_name, GetIndStr(128, 25)));
  365.                 SetItemText(modal, ditPostCreator, MapOSType(entry.post_creator));
  366.             end
  367.             else begin
  368.                 SetDCtlTitle(modal, ditPostButton, GetIndStr(128, 23));
  369.                 SetItemText(modal, ditPostCreator, '');
  370.             end;
  371.             SetDCtlBoolean(modal, ditPost, btst(entry.flags, ICmap_post_bit));
  372.         end;
  373.  
  374.         var
  375.             err: OSErr;
  376.             item: integer;
  377.             flags: longint;
  378.             tmpstr: Str255;
  379.             dummy: boolean;
  380.             saved_state: Ptr;
  381.     begin
  382.         err := noErr;
  383.         modal := GetNewDialog(700, nil, WindowPtr(-1));
  384.         if modal = nil then begin
  385.             err := memFullErr;
  386.         end; (* if *)
  387.         if err = noErr then begin
  388.             SetUpDefaultOutline(modal, ditOK, ditEditorUserItem);
  389.             SetItemText(modal, ditEntryName, entry.entry_name);
  390.             SetItemText(modal, ditExtension, entry.extension);
  391.             SetItemText(modal, ditMIMEType, entry.MIME_type);
  392.             SetDCtlBoolean(modal, ditAsciiRadio, not btst(entry.flags, ICmap_binary_bit));
  393.             SetDCtlBoolean(modal, ditBinaryRadio, btst(entry.flags, ICmap_binary_bit) and not (btst(entry.flags, ICmap_resource_fork_bit)));
  394.             SetDCtlBoolean(modal, ditMacintoshRadio, btst(entry.flags, ICmap_binary_bit) and (btst(entry.flags, ICmap_resource_fork_bit)));
  395.             SetDCtlBoolean(modal, ditNotForIncoming, btst(entry.flags, ICmap_not_incoming_bit));
  396.             SetDCtlBoolean(modal, ditNotForOutgoing, btst(entry.flags, ICmap_not_outgoing_bit));
  397.             SetItemText(modal, ditType, MapOSType(entry.file_type));
  398.             SetItemText(modal, ditCreator, MapOSType(entry.file_creator));
  399.             SetItemText(modal, ditApplicationName, entry.creator_app_name);
  400.             SetPostInfo;
  401.             SelIText(modal, ditEntryName, 0, 32767);
  402.             ShowWindow(modal);
  403.             DisableMenuBar(saved_state, -1);
  404.             InitCursor;
  405.             repeat
  406.                 MovableModalDialog(@AddChangeFilter, item);
  407.                 case item of
  408.                     ditAsciiRadio..ditMacintoshRadio:  begin
  409.                         SetRadio(modal, item);
  410.                     end;
  411.                     ditNotForIncoming..ditNotForOutgoing:  begin
  412.                         ToggleDCtlBoolean(modal, item);
  413.                     end;
  414.                     ditChooseExample:  begin
  415.                         if IsKeyDown(kOptionKeyCode) then begin
  416.                             DoEditTypeCreator;
  417.                         end
  418.                         else begin
  419.                             DoChooseExample;
  420.                         end; (* if *)
  421.                     end;
  422.                     ditPost:  begin
  423.                         if not btst(entry.flags, ICmap_post_bit) then begin
  424.                             if (entry.post_creator = OSType(0)) then begin
  425.                                 if entry.file_creator <> OSType(0) then begin
  426.                                     entry.post_creator := entry.file_creator;
  427.                                     entry.post_app_name := entry.creator_app_name;
  428.                                 end
  429.                                 else begin
  430.                                     dummy := ChoosePost;
  431.                                 end;
  432.                             end;
  433.                             if entry.post_creator <> OSType(0) then begin
  434.                                 bset(entry.flags, ICmap_post_bit);
  435.                             end;
  436.                         end
  437.                         else begin
  438.                             bclr(entry.flags, ICmap_post_bit);
  439.                         end;
  440.                         SetPostInfo;
  441.                     end;
  442.                     ditPostButton:  begin
  443.                         if ChoosePost then begin
  444.                             bset(entry.flags, ICmap_post_bit);
  445.                         end;
  446.                         SetPostInfo;
  447.                     end;
  448.                     otherwise
  449.                         ;
  450.                 end; (* case *)
  451.             until item in [ditOK, ditCancel];
  452.             if item = ditOK then begin
  453.                 GetItemText(modal, ditEntryName, entry.entry_name);
  454.                 GetItemText(modal, ditExtension, entry.extension);
  455.                 GetItemText(modal, ditMIMEType, entry.MIME_type);
  456.  
  457.                 flags := band(entry.flags, BNOT(ICmap_binary_mask + ICmap_data_fork_mask + ICmap_resource_fork_mask + ICmap_not_incoming_mask + ICmap_not_outgoing_mask));
  458.                 flags := flags + ICmap_data_fork_mask;
  459.                 if not GetDCtlBoolean(modal, ditAsciiRadio) then begin
  460.                     flags := flags + ICmap_binary_mask;
  461.                 end; (* if *)
  462.                 if GetDCtlBoolean(modal, ditMacintoshRadio) then begin
  463.                     flags := flags + ICmap_resource_fork_mask;
  464.                 end; (* if *)
  465.                 if GetDCtlBoolean(modal, ditNotForIncoming) then begin
  466.                     flags := flags + ICmap_not_incoming_mask;
  467.                 end; (* if *)
  468.                 if GetDCtlBoolean(modal, ditNotForOutgoing) then begin
  469.                     flags := flags + ICmap_not_outgoing_mask;
  470.                 end; (* if *)
  471.                 entry.flags := flags;
  472.  
  473.                 GetItemText(modal, ditType, tmpstr);
  474.                 entry.file_type := MapStr(tmpstr);
  475.                 GetItemText(modal, ditCreator, tmpstr);
  476.                 entry.file_creator := MapStr(tmpstr);
  477.                 GetItemText(modal, ditApplicationName, entry.creator_app_name);
  478.             end
  479.             else begin
  480.                 err := userCanceledErr;
  481.             end; (* if *)
  482.         end; (* if *)
  483.         if modal <> nil then begin
  484.             ReEnableMenuBar(saved_state);
  485.             DisposeDialog(modal);
  486.         end; (* if *)
  487.         DoDialog := err;
  488.     end; (* DoDialog *)
  489.  
  490.     function DoAddChange (selection: integer; var entry: ICMapEntry; entries: Handle; lh: ListHandle): OSErr;
  491.         var
  492.             junkint: integer;
  493.             err: OSErr;
  494.             pos: longint;
  495.             app_fss: FSSpec;
  496.     begin
  497.         if selection = -1 then begin
  498.             with entry do begin
  499.                 version := 0;
  500.                 file_type := OSType(0);
  501.                 file_creator := OSType(0);
  502.                 post_creator := OSType(0);
  503.                 flags := 0;
  504.                 extension := '';
  505.                 creator_app_name := '';
  506.                 post_app_name := '';
  507.                 MIME_type := '';
  508.                 entry_name := '';
  509.             end; (* with *)
  510.             err := noErr;
  511.         end
  512.         else begin
  513.             err := ICMapErr(ICGetIndMapEntry(GetInstance, entries, selection + 1, pos, entry));
  514.         end; (* if *)
  515.  
  516.         if err = noErr then begin
  517.             err := DoDialog(entry);
  518.         end; (* if *)
  519.  
  520.         if err = noErr then begin
  521.             if selection = -1 then begin
  522.                 err := ICMapErr(ICAddMapEntry(GetInstance, entries, entry));
  523.                 if err = noErr then begin
  524.                     junkint := LAddRow(1, 32767, lh);
  525.                 end; (* if *)
  526.             end
  527.             else begin
  528.                 err := ICMapErr(ICSetMapEntry(GetInstance, entries, pos, entry));
  529.             end; (* if *)
  530.         end; (* if *)
  531.         DoAddChange := err;
  532.     end; (* DoAddChange *)
  533.  
  534.     function WhatClickFileMap (wt: WindowType; item: integer; er: eventRecord): OSErr;
  535.         var
  536.             lh: ListHandle;
  537.             entry: ICMapEntry;
  538.             entries: Handle;
  539.             selection: integer;
  540.             err: OSErr;
  541.             pos: longint;
  542.             r: Rect;
  543.     begin
  544.         entries := Handle(windowinfo[wt].items[ditList]^.data);
  545.         lh := ListHandle(windowinfo[wt].items[ditList]^.spare_data);
  546.         GlobalToLocal(er.where);
  547.         selection := SelectedLine(lh);
  548.         err := 1;
  549.         case item of
  550.             ditAdd: 
  551.                 err := DoAddChange(-1, entry, entries, lh);
  552.             ditChange: 
  553.                 err := DoAddChange(selection, entry, entries, lh);
  554.             ditDelete: 
  555.                 if selection <> -1 then begin
  556.                     err := ICMapErr(ICGetIndMapEntry(GetInstance, entries, selection + 1, pos, entry));
  557.                     if err = noErr then begin
  558.                         err := ICMapErr(ICDeleteMapEntry(GetInstance, entries, pos));
  559.                     end; (* if *)
  560.                     if err = noErr then begin
  561.                         LDelRow(1, selection, lh);
  562.                     end; (* if *)
  563.                 end; (* if *)
  564.             ditList:  begin
  565.                 if LClick(er.where, 0, lh) then begin
  566.                     if IsLocked(wt, item) then begin
  567.                         LockedAlert(wt, item);
  568.                         err := userCanceledErr;
  569.                     end
  570.                     else begin
  571.                         FlashItem(windowinfo[wt].window, ditChange);
  572.                         err := DoAddChange(SelectedLine(lh), entry, entries, lh);            (* selection may have been changed by LClick *)
  573.                     end; (* if *)
  574.                 end; (* if *)
  575.             end;
  576.         end; (* case *)
  577.         if err = noErr then begin
  578.             DirtyDocument;
  579.         end; (* if *)
  580.         if err = 1 then begin
  581.             err := noErr;
  582.         end; (* if *)
  583.         DimButtons(wt);
  584.         WhatClickFileMap := err;
  585.     end; (* WhatClickFileMap *)
  586.  
  587.     function WhatFlushFileMap (wt: WindowType; item: integer): OSErr;
  588.     begin
  589.         WhatFlushFileMap := ICMapErr(ICSetPrefHandle(GetInstance, windowinfo[wt].items[item]^.key, ICattr_no_change, Handle(windowinfo[wt].items[item]^.data)));
  590.     end; (* WhatFlushFileMap *)
  591.  
  592.     function WhatCloseFileMap (wt: WindowType; item: integer): OSErr;
  593.     begin
  594.         LDispose(ListHandle(windowinfo[wt].items[item]^.spare_data));
  595.         DisposeHandle(Handle(windowinfo[wt].items[item]^.data));
  596.         WhatCloseFileMap := noErr;
  597.     end; (* WhatCloseFileMap *)
  598.  
  599.     function WhatActivateFileMap (wt: WindowType; item: integer; activate: boolean): OSErr;
  600.     begin
  601.         LActivate(activate, ListHandle(windowinfo[wt].items[item]^.spare_data));
  602.         WhatActivateFileMap := noErr;
  603.     end; (* WhatActivateFileMap *)
  604.  
  605.     function GetEntryName (list: ListHandle; c: cell): str255;
  606.         var
  607.             entry: ICMapEntry;
  608.             err: OSErr;
  609.             junkpos: longint;
  610.             entries: handle;
  611.     begin
  612.         GetEntryName := '';
  613.         entries := Handle(windowinfo[GetWindowType(list^^.port)].items[ditList]^.data);
  614.         err := ICMapErr(ICGetIndMapEntry(GetInstance, entries, c.v + 1, junkpos, entry));
  615.         if err = noErr then begin
  616.             GetEntryName := concat(entry.creator_app_name, GetAString(128, 5), entry.entry_name);
  617.         end;
  618.     end;
  619.  
  620.     function WhatKeyFileMap (wt: WindowType; item: integer; er: EventRecord): OSErr;
  621.         var
  622.             ch: integer;
  623.             changed: boolean;
  624.             entry: ICMapEntry;
  625.             lh: ListHandle;
  626.             err: OSErr;
  627.     begin
  628.         lh := ListHandle(windowinfo[wt].items[ditList]^.spare_data);
  629.         err := noErr;
  630.         if (er.what = keyDown) or (er.what = autoKey) then begin
  631.             ch := BAND(er.message, $FF);
  632.             case ch of
  633.                 crChar, enterChar:  begin
  634.                     if GetDCtlEnable(windowinfo[wt].window, ditChange) then begin
  635.                         FlashItem(windowinfo[wt].window, ditChange);
  636.                         err := DoAddChange(SelectedLine(lh), entry, Handle(windowinfo[wt].items[ditList]^.data), lh);
  637.                         if err = noErr then begin
  638.                             DirtyDocument;
  639.                         end;
  640.                     end; (* if *)
  641.                 end;
  642.                 otherwise begin
  643.                     DoListKey(lh, er.modifiers, chr(BAND(er.message, $FF)), @GetEntryName);
  644.                     DimButtons(wt);
  645.                 end;
  646.             end;
  647.         end;
  648.         WhatKeyFileMap := err;
  649.     end; (* WhatKeyFileMap *)
  650.  
  651.     function WhatCursorFileMap (wt: WindowType; item: integer; pt: Point; cursorid: integer): OSErr;
  652.         var
  653.             r: Rect;
  654.     begin
  655.         GetDItemRect(windowinfo[wt].window, item, r);
  656.         InsetRect(r, 15, 0);
  657.         if PtInRect(pt, r) then begin
  658.             SetCursor(GetCursor(cursorid)^^);
  659.         end
  660.         else begin
  661.             InitCursor;
  662.         end; (* if *)
  663.     end; (* WhatCursorFileMap *)
  664.  
  665. end. (* ICFileMapWhat *)